<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>24.flatern数组拍平</title>
</head>

<body>

  <script>
    function flatern(arr) {

      const isDeep = arr.some(item => {
        return item instanceof Array
      })

      if (!isDeep) {
        return arr
      }
      // concat 可以拍平一层嵌套
      const res = Array.prototype.concat.apply([], arr)
      return flatern(res) // 递归
    }

    console.log(flatern([1, 2, 3, [5, [7, 8]]]));
  </script>

</body>

</html>